with open('favorite_foods.txt', 'a',encoding='utf-8') as file:
    while True:
        food = input("请输入你最喜欢的食物（若想结束输入，可直接按回车键）：")
        if food == "":
            break
        file.write(food + '\n')